﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace EvoSim.Simulation
{
	public class Entity
	{
		public string EntityName;
		public World World;

		double posX;
		public double PosX
		{
			get { return posX; }
			set
			{
				posX = value;

				if (World.WorldHasEdges)
				{
					if (posX < 0)
						posX = 0;
					else if (posX > World.Width)
						posX = World.Width;
				}
				else
				{
					if (posX < 0)
						posX = World.Width + posX;
					else if (posX > World.Width)
						posX = posX - World.Width;
				}
			}
		}
		double posY;
		public double PosY
		{
			get { return posY; }
			set
			{
				posY = value;

				if (World.WorldHasEdges)
				{
					if (posY < 0)
						posY = 0;
					else if (posY > World.Height)
						posY = World.Height;
				}
				else
				{
					if (posY < 0)
						posY = World.Height + posY;
					else if (posY > World.Height)
						posY = posY - World.Height;
				}
			}
		}
		double rotation;
		public double Rotation
		{
			get { return rotation; }
			set
			{
				rotation = value;

				if (rotation < 0)
					rotation = Math.PI * 2 + rotation;
				else if (rotation > Math.PI * 2)
					rotation = rotation - Math.PI * 2;
			}
		}

		public Color EntityColor;
		public virtual int Radius { get; set; }
		public int Age;

		public bool IsDead { get; private set; }

		public Entity(string name)
		{
			EntityName = name;
		}

		public virtual void Update(GameTime gameTime)
		{
			Age += 1;
		}

		public void Kill()
		{
			IsDead = true;
		}
	}
}
